package ModelLayer;
import java.util.ArrayList;
import java.text.SimpleDateFormat;

public class DVD
{
    private int id;
    private String title;
    private String artist;
    private long publicationDate;
    private ArrayList<Copy> copies;

    public DVD(int id, String title, String artist, long publicationDate)
    {
        this.id = id;
        this.title = title;
        this.artist = artist;
        this.publicationDate = publicationDate;
        copies = new ArrayList<Copy>();

    }
    public DVD ()
    {
    }
    
    
    public void setId(int id)
    {
        this.id = id;
    }

    public int getId()
    {
        return id;
    }

    public void setTitle(String title)
    {
        this.title = title;
    }

    public String getTitle()
    {
        return title;
    }

    public void setArtist(String artist)
    {
        this.artist = artist;
    }

    public String getArtist()
    {
        return artist;
    }

    public void setPublicationDate(long publicationDate)
    {
        this.publicationDate = publicationDate;
    }

    public long getPublicationDate()
    {
        return publicationDate;
    }

    public void printDVDInfo()
    {
        SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
        System.out.println("Id: " + id);
        System.out.println(" Title: " + title);
        System.out.println(" Artist: " + artist );
        System.out.println(" Publication Date: " + formatter.format(publicationDate));
        System.out.println("");
    }

    public String getDVDInfo()
    {
        SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
        return "Id: " + id + "\n Title: " + title + "\n Artist: " + artist +  "\n Publication Date: " + formatter.format(publicationDate) + "\n";
    }

    public void printAllCopies()
    {
        for(Copy copy : copies)
        {
            copy.printCopyInfo();
        }
    }

    public void createCopy(long serialNr, long purchaseDate, int purchasePrice)//add copies to the DVD
    {
        Copy copy = new Copy (serialNr, purchaseDate, purchasePrice, this);
        copies.add(copy);
    }

    public Copy getCopy(long serialNr)
    {
        for (Copy copy : copies) {
            if (copy.getSerialNumber() == serialNr) 
                return copy;

        }
        return null;
    }

    public void updateCopy(int choise, long serialNr, String value)
    {
        Copy copy = getCopy(serialNr); //id is the id number of the DVD
        if (copy != null) {
            if(choise == 1)
            {
                copy.setPurchaseDate(Long.parseLong(value));
            }
            if(choise == 2)
            {
                copy.setPurchasePrice(Long.parseLong(value));
            }

        }
    }

    public void deleteCopy(long serialNr)
    {
        Copy copy = getCopy(serialNr);
        if ( copy!= null)
            copies.remove(copy);

    }

}
